package com.fingard.avatar.website.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.fingard.avatar.website.model.bean.PageView;
import com.fingard.avatar.website.model.bean.ResultContext;
import com.fingard.avatar.website.model.dto.IdDto;
import com.fingard.avatar.website.model.dto.UserAddDto;
import com.fingard.avatar.website.model.dto.UserPageDto;
import com.fingard.avatar.website.model.po.SysUserPo;
import com.fingard.avatar.website.service.SysUserService;
import io.swagger.annotations.Api;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 徐一涛
 * @date 2022-04-26
 */
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("user")
@Api(tags = "用户相关接口")
public class SysUserController {
    private final SysUserService sysUserService;

    @PostMapping(value = {"/add"})
    public ResultContext<Boolean> add(@Validated UserAddDto req) {
        return ResultContext.success(sysUserService.add(req));
    }

    @PostMapping(value = {"/delete"})
    public ResultContext<Boolean> delete(@Validated IdDto req) {
        return ResultContext.success(sysUserService.delete(req));
    }

    @PostMapping(value = {"/page"})
    public PageView<SysUserPo> page(@Validated UserPageDto req) {
        IPage<SysUserPo> iPage = sysUserService.page(req);
        return PageView.success(iPage);
    }
}
